<?php defined( 'BASEPATH' ) or die( 'Restricted' ); ?>

<? echo "<?php defined( 'BASEPATH' ) or die( 'Restricted' );"; ?>

/*
-----------------------------------------------------------------------------
| This file is copyright 2011 by ALL RIGHTS RESERVED.
|----------------------------------------------------------------------------
| Controller: <?= $ds->controller; ?>

Regenerate URL:
<?= URL( $page )->setVar( 'h', base64_encode( serialize( $ds->dataArray() ) ) ) . "\n\n"; ?>
|----------------------------------------------------------------------------
| Date			| Person		| Change Description
|----------------------------------------------------------------------------
| <?= date::currentDate(); ?>	| <?= $ds->developer; ?>	| Created
-----------------------------------------------------------------------------
*/
<?php if ( $ds->exists( 'require_login' ) ) : ?>
AUTH()->requireLogin();
AUTH()->minRole( <?= $ds->min_role; ?> );
<?php endif; ?>

//------------------------------------------------------------------------

$form = load_form( '<?= $ds->form; ?>' );
<?php if ( $ds->isEmpty( 'cancel_url' ) == false ) : ?>
$form->cancelUrl = URL( '<?= $ds->cancel_url; ?>' );
<?php endif; ?>

<?= $ds->modelVarName; ?> = load_model( '<?= $ds->model; ?>' );

if ( POST()->dataPresent )
{
	$form->ds( clone POST() );
	$form->validate();

	if ( $form->valid )
	{
		try
		{
			dbm()->beginTransaction();
			<?= $ds->modelVarName; ?>-><?= $ds->model_action; ?>( $form->ds );
			dbm()->commit();
		}
		catch ( Exception $e )
		{
			dbm()->rollback( $e );
			show_error( '<?= $ds->error_message; ?>', $e );
		}

		URL( '<?= $ds->success_url; ?>' )<?

		if ( !$ds->isEmpty( 'success_msg' ) )
		{
			?>->setVar( 'msg', '<?= $ds->success_msg; ?>' )<?
		}
		?>->redirect();
	}
}

//------------------------------------------------------------------------

$windowTitle = '<?= $ds->window_title; ?>';
$breadcrumbHtml = BREADCRUMB( $windowTitle )->render();

<?
foreach( $ds->extraJs as $extraJs )
{
	?>$extraJs[] = <?= trim( $extraJs ) . ';'; ?>

<?
}
?>
<?
foreach( $ds->extraCss as $extraCss )
{
	?>$extraCss[] = <?= trim( $extraCss ) . ';'; ?>

<?
}
?>

include view( 'header' );
include view( '<?= $ds->view; ?>' );
include view( 'footer' );
